<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>文档详情</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="keywords" content="fly,layui,前端社区">
  <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
  <link rel="stylesheet" href="../../res/layui/css/layui.css">
  <link rel="stylesheet" href="../../res/css/global2.css">
  <script src="/js/jquery.min.js"></script>
  <script src="/js/common.variate.js"></script>
  <script src="/js/common.method.js"></script>
  <link rel="stylesheet" href="/css/header.css">
  <script src="/js/jquery.min.js"></script>
  <script src="/lib/marked.min.js"></script>
  <script src="/lib/prettify.min.js"></script>
  <script src="/lib/raphael.min.js"></script>
  <script src="/lib/underscore.min.js"></script>
  <script src="/lib/sequence-diagram.min.js"></script>
  <script src="/lib/flowchart.min.js"></script>
  <script src="/lib/jquery.flowchart.min.js"></script>
  <script src="/js/editormd.js"></script>
  <link rel="stylesheet" href="/css/editormd.preview.css" />
  <style>
    .editormd-html-preview {
      width: 90%;
      margin: 0 auto;
    }
  </style>
  <style>
    html, body {
      overflow-x: inherit;
    }
    .fly-extend-detail{
      padding-bottom: 0px;
    }
    .updata{
      height: 30px;
      line-height: 30px;
      background-color: #3a9dff;
    }
    .delete{
      height: 30px;
      line-height: 30px;
      background-color: #ff3535;
    }
    .download{
      height: 30px;
      line-height: 30px;
      background-color: #00ce46;
    }
  </style>
</head>
<body>

<div class="fly-header layui-bg-black">
  <div class="layui-container">
    <a class="fly-logo" href="/">
      <img src="/images/logo.png" alt="layui" style="width: 105px;">
    </a>
    <ul class="layui-nav fly-nav-user" id="tabYe">

    </ul>
  </div>
</div>

<div class="fly-extend-detail layui-card">
  <div class="layui-container">
    <div class="fly-extend-list-header">
      <h1 class="fly-extend-title layui-elip">
        <a th:text="${title}"></a>
        <span class="layui-badge layui-bg-green layui-hide-xs" th:each="label:${labels}"><p th:text="${label}"></p></span>
      </h1>
      <div class="fly-extend-list-info">
        <a target="_blank" class="fly-extend-list-user" title="发布者"> <cite class="layui-hide-xs" th:text="${userName}"></cite></a>
      </div>
    </div>
    <p class="fly-extend-list-desc" th:text="${description}"></p>
    <div class="layui-form-item" style="padding: 5px;padding-top: 20px;padding-bottom: 10px;text-align: right;">
      <button id="delete" class="layui-btn delete" lay-filter="*" lay-button="" onclick="delDoc()" style="display: none;">删除</button>
      <button id="updata" class="layui-btn updata" lay-filter="*" lay-button="" onclick="updateDoc()" style="display: none;">修改</button>
      <button class="layui-btn download" lay-filter="*" lay-button="" onclick="downloadDoc()">下载</button>
    </div>
    <div class="layui-btn-container layui-extend-doc-edit">
    </div>
  </div>
</div>


<div class="layui-container">
  <div class="layui-row layui-col-space20">
    <div class="layui-col-sm9 layui-col-md10" style="width: 100%">
      <div class="layui-card fly-extend-doc layui-show">
        <div class="layui-card-header">
          <h3 class="layui-inline layui-this">文档</h3>
        </div>
        <div id="content" class="layui-card-body detail-body photos layui-text" th:text="${content}">
        </div>
      </div>
    </div>
  </div>
</div>

<div class="fly-footer">
  <p> 2018 &copy; <a href="https://gitee.com/chaofan2685_admin" target="_blank">炒饭 出品</a></p>
  <p>
    <a href="http://www.lishiots.com/" target="_blank">力石科技</a>
    <a href="tencent://message/?uin=894195915&Site=http://vps.shuidazhe.com&Menu=yes">交个朋友</a>
    <a href=mailto:chaofan2685@qq.com>问题反馈</a>
  </p>
</div>

<script src="../../res/layui/layui.all.js"></script>
<script>
    checkLogin3();
    var contentType = '[(${contentType})]';

    layui.cache.page = 'jie';
    layui.cache.user = {
      username: '游客'
      ,uid: -1
      ,avatar: '../../res/images/avatar/00.jpg'
      ,experience: 83
      ,sex: '男'
    };
    layui.config({
      version: "3.0.0"
      ,base: '../../res/mods/'
    }).extend({
      fly: 'index'
    }).use(['fly', 'face'], function(){
      var $ = layui.$
      ,fly = layui.fly;
      //如果你是采用模版自带的编辑器，你需要开启以下语句来解析。
      if (contentType == "NT"){
          $('.detail-body').each(function(){
              var othis = $(this), html = othis.html();
              othis.html(fly.content(html));
          });
      }
    });

    if (contentType == "MD"){
        var markdownString = $("#content").text();
        $("#content").html("");
        editormd.markdownToHTML("content", {
            markdown        : markdownString,
            htmlDecode      : "style,script,iframe",  // you can filter tags decode
            emoji           : true,
            taskList        : true,
            tex             : true,  // 默认不解析
            flowChart       : true,  // 默认不解析
            sequenceDiagram : true,  // 默认不解析
        });
    }

    function delDoc() {
        layer.msg('是否删除该文档？', {
            anim: 6,
            time: 0 //不自动关闭
            ,btn: ['确定', '取消']
            ,yes: function(index){
                layer.close(index);
                var docId = '[(${docId})]';
                $.ajax({
                    type: "GET",
                    url: "/api/doc/delete",
                    data: {id:docId},
                    dataType: "json",
                    success: function(data){
                        if (data.code == "8200"){
                            location.href = "/index.html";
                        }else {
                            layer.alert(data.message, {icon: 2});
                        }
                    }
                });
            }
        });
    }

    function updateDoc() {
        var docId = '[(${docId})]';
        location.href = "/update/"+docId;
    }

    function downloadDoc() {
        var gitlaburl = '[(${gitlaburl})]';
        // location.href = gitlaburl;
        window.open(gitlaburl);
    }

    function checkAuthority(userId) {
        var docUserId = '[(${userId})]';
        if (userId == docUserId){
            $("#updata").show();
            $("#delete").show();
        }
    }

</script>

</body>
</html>